package com.station.service.mapper;

import com.station.annotation.DataSource;
import com.station.vo.PurchDetail;
import com.station.vo.PurchOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: newblderp
 * @BelongsPackage: com.station.service.mapper
 * @Author: songhui
 * @CreateTime: 2025-10-21  09:28
 * @Description: TODO
 * @Version: 1.0
 */
@Mapper
public interface PurchaseMapper {

    @DataSource("erp")
    @Select(" select \n" +
            " * \n" +
            "  from purchorder pur \n" +
            "where \n" +
            " pur.vendorId = #{vendorId} \n" +
            " and pur.df = 0\n" +
            " and pur.reviewTime >= STR_TO_DATE(#{startDate},'%Y-%m-%d %H:%i:%s')\n" +
            " and pur.reviewTime <= STR_TO_DATE(#{endDate},'%Y-%m-%d %H:%i:%s') \n" +
            " and pur.state=2 and pur.orderType=0 ")
    List<PurchOrder> queryInStockOrderList(@Param("vendorId")Long vendorId, @Param("startDate") String startDate, @Param("endDate") String endDate);


    @DataSource("erp")
    @Select("select " +
            "* " +
            "from purchdetail " +
            "where orderNo = #{orderNo} and df=0 ")
    List<PurchDetail> queryOrderDetailList(String orderNo);

    @DataSource("erp")
    @Select(" select \n" +
            " * \n" +
            "  from purchorder pur \n" +
            "where \n" +
            " pur.vendorId = #{vendorId} \n" +
            " and pur.df = 0\n" +
            " and pur.isPrepaid = #{isPrepaid} \n" +
            " and pur.orderNo = #{orderNo} ")
    PurchOrder queryOrderByOrderNo(@Param("vendorId")Long vendorId, @Param("orderNo") String orderNo, @Param("isPrepaid") Integer isPrepaid);


    @DataSource("erp")
    @Select(" select \n" +
            " * \n" +
            "  from purchorder pur \n" +
            "where \n" +
            " pur.vendorId = #{vendorId} \n" +
            " and pur.df = 0\n" +
            " and pur.reviewTime >= STR_TO_DATE(#{startDate},'%Y-%m-%d %H:%i:%s')\n" +
            " and pur.reviewTime <= STR_TO_DATE(#{endDate},'%Y-%m-%d %H:%i:%s') \n" +
            " and pur.state=2 and pur.orderType=2 and pur.isPrepaid = 0")
    List<PurchOrder> queryOrderList(@Param("vendorId")Long vendorId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    @DataSource("erp")
    @Select(" select \n" +
            " * \n" +
            "  from purchorder pur \n" +
            "where \n" +
            " pur.vendorId = #{vendorId} \n" +
            " and pur.df = 0\n" +
            " and pur.reviewTime >= STR_TO_DATE(#{startDate},'%Y-%m-%d %H:%i:%s')\n" +
            " and pur.reviewTime <= STR_TO_DATE(#{endDate},'%Y-%m-%d %H:%i:%s') \n" +
            " and pur.state=2 and pur.orderType=1 ")
    List<PurchOrder> queryPurchaseReturnOrderList(@Param("vendorId")Long vendorId, @Param("startDate") String startDate, @Param("endDate") String endDate);
}
